package com.it.stringdemo;

import java.util.Scanner;

import java.util.Scanner;

public class stringdome5 {
    public static void main(String[] args) {
        //金额转换
        //2135
        //贰壹叁伍
        //零零零贰壹叁伍
        //零佰零拾零万贰仟壹佰叁拾伍元

        //键盘录入一个金额
        Scanner sc = new Scanner(System.in);
        int money;
        while(true) {
            System.out.println("请输入一个整数：");
            money = sc.nextInt();
            if (money >= 0 && money <= 9999999) {
                break;
            } else {
                System.out.println("金额无效");
            }
        }
        //定义一个变量用来表示钱的大写
        String moneyStr = "";
        //2.得到money里面的每一位数字
        while(true) {
            //从右往左获取数据
            int ge = money%10;
            //System.out.println(ge);
            String capitalNumber = getCapitalNumber(ge);
            moneyStr = capitalNumber + moneyStr;
            //去掉刚刚获取的数据
            money = money/10;
            //如果数字上的每一个都获取了，那么money记录的就是0，此时循环结束
            if(money == 0){
                break;
            }
        }
        //System.out.println(moneyStr);
        //3.在前面补0，补齐7位
        int count = 7-moneyStr.length();
        for (int i = 0; i < count; i++) {
            moneyStr = "零"+ moneyStr;
        }
        System.out.println(moneyStr);

        //输入单位
        //定义一个数组表示单位
        String result = "";
        String[] arr = {"佰","拾","万","仟","佰","拾","元"};
        for (int i = 0; i < moneyStr.length(); i++) {
            char c = moneyStr.charAt(i);
            //System.out.print(c);
            //System.out.print(arr[i]);
            result = result + c + arr[i];
        }
        //5.打印的最终结果
        System.out.println(result);
    }
    //定义一个方法把数字变成大写的中文
    public static String getCapitalNumber(int number) {
        //定义数组，让数字跟大写的中文产生一个对应关系
        String[] arr = {"零","壹","贰","叁","肆","伍","陆","柒","捌","玖"};
        //返回结果
        return arr[number];
    }
}
